-- Gamemode

-- CONTROLLER

function StartRide(entity, startname, delay)
	for k,v in pairs(ents.FindByName(entity)) do v:Fire(startname, 1, delay) end
end

function StopRide(entity, endname, delay)
	for k,v in pairs(ents.FindByName(entity)) do v:Fire(endname, 1, delay) end
end

function SetSpeed(entity, speedname, speed, delay)
	for k,v in pairs(ents.FindByName(entity)) do v:Fire(speedname, speed, delay) end
end

function StartCycle(entity)
	entity()
end

-- RIDES

function PirateShip()
local push = ents.FindByName("thruster")

	StartRide("thruster", "Activate", 0)
	
	timer.Simple(math.random(1,5), function()
					StopRide("thruster", "Deactivate", 0) 
					timer.Simple(math.random(1,5), function()
									push[1]:SetKeyValue("force", -800)
									StartRide("thruster", "Activate", 0)
									timer.Simple(math.random(1,5), function()
													StopRide("thruster", "Deactivate", 0)
													timer.Simple(math.random(1,5), function()
																	push[1]:SetKeyValue("force", 800)
																	StartRide("thruster", "Activate", 0)
																	timer.Simple(math.random(1,5), function()
																					StopRide("thruster", "Deactivate", 0)
																					local ship = ents.FindByName("ship")
																					ship[1]:SetPos(Angle(0.0000, -23.5480, -204.1242))			
																					end)
																	end)
													end)
									end)
					end)
	
end